<?php


class Category_model extends CI_Model
{
	function __construct()
	{
		parent::__construct();
		$this->load->database();//加载数据库
	}

	/**
	 * 新闻列表
	 */
	public function lists()
	{
		$list = $this->db->get('category', 0, 20)->result_array();
		return list_to_tree($list, 'id', 'upid');
	}

	/**
	 * 数据添加
	 * @param $data
	 * @return mixed
	 */
	public function insert($data)
	{
		return $this->db->insert('category', $data);
	}

	/**
	 * 数据修改
	 * @param $id
	 * @param $data
	 * @return mixed
	 */
	public function update($id, $data)
	{
		return $this->db->where('id', $id)->update('Category', $data);
	}


	public function info($id, $type = 1)
	{
		$map = array();
		switch ($type) {
			case 1:
				$map['id'] = $id;
				break;
			case 2:
				$map['ename'] = $id;
				break;
			default:
				return 0; //参数错误
		}
		return $this->db->get_where('category', $map)->row_array();
	}

	public function delete($id)
	{

	}
}
